<template>
    <div class="levle">
        <h1>医院</h1>
        <div class="contend">
            <div class="left">
                等级:
            </div>
            <ul class="hospatel">
                <li :class="{active:activeFlag==''}" @click="changeLevel('')">全部</li>
                <li v-for="item in HospitalLevel" :key="item.id" @click="changeLevel(item.value)" :class="{active:activeFlag==item.value}">{{ item.name }}</li>
              
            </ul>
        </div>
    </div>
</template>

<script setup lang="ts">
//引入组合式api
import { onMounted, ref } from 'vue';
//引入接口函数
import { reqGetHospitalLevel } from '@/api/home';
//引入接口约束
import { HospitalLevelData,HospitalLevelArr } from '@/api/home/type';
//接收返回的医院数据
let HospitalLevel = ref<HospitalLevelArr>([]);
//控制等级高亮效果
let activeFlag = ref<string>('');
//接收自定义事件
let $emit = defineEmits(['getLevel']);
//挂载时获取数据
onMounted(()=>{
    HasHospitalLevel();
})
//获取医院等级与地区的回调
const HasHospitalLevel = async()=>{
    let reslut:HospitalLevelData = await reqGetHospitalLevel("Hostype");
   if(reslut.code == 200) {
    HospitalLevel.value = reslut.data;
   }
    
}
//等级发生改变的回调
const changeLevel = (value:string)=>{
    activeFlag.value = value;
    //调用自定义事件
    $emit('getLevel',activeFlag.value)
}
</script>
<script lang="ts">
export default {
    name: 'HospitalLevel',
}
</script>

<style scoped lang="scss">
    .levle {
        margin: 10px 0;
        color:#7f7f7f;
        h1 {
            margin:10px 0px;
        }
        .contend {
            display: flex;
            .hospatel {
                display: flex;
                li {
                    margin-right: 10px;
                    &.active {
                        color: #55a6fe;
                    }
                }
                li:hover {
                    color: #55a6fe;
                    cursor: pointer;
                }
             
            }
            .left {
                margin-right: 10px;
            }
        }
    }
</style>